import { NextRequest, NextResponse } from 'next/server'; import { ResultDto } from '@/types/response/common'; import { fetchJson } from '@/lib/utils/server'; export async function GET(request: NextRequest, { params }: { params: Promise<{ path?: string[] }> }) { const { path } = await params; const endpoint = `/api/forum/comments/${(path ?? []).join('/')}`; const url = new URL(request.url); const res: ResultDto = await fetchJson(`${endpoint}${url.search}`, { method: 'GET' }); return NextResponse.json(res); } export async function POST(request: NextRequest, { params }: { params: Promise<{ path?: string[] }> }) { const { path } = await params; const endpoint = `/api/forum/comments/${(path ?? []).join('/')}`; const contentType = request.headers.get('content-type') || ''; if (contentType.includes('multipart/form-data')) { const res: ResultDto = await fetchJson(endpoint, { method: 'POST', body: await request.arrayBuffer(), headers: { 'Content-Type': contentType } }); return NextResponse.json(res); } const res: ResultDto = await fetchJson(endpoint, { method: 'POST', body: JSON.stringify(await request.json()) }); return NextResponse.json(res); } export async function PUT(request: NextRequest, { params }: { params: Promise<{ path?: string[] }> }) { const { path } = await params; const endpoint = `/api/forum/comments/${(path ?? []).join('/')}`; const contentType = request.headers.get('content-type') || ''; if (contentType.includes('multipart/form-data')) { const res: ResultDto = await fetchJson(endpoint, { method: 'PUT', body: await request.arrayBuffer(), headers: { 'Content-Type': contentType } }); return NextResponse.json(res); } const res: ResultDto = await fetchJson(endpoint, { method: 'PUT', body: JSON.stringify(await request.json()) }); return NextResponse.json(res); } export async function DELETE(_: NextRequest, { params }: { params: Promise<{ path?: string[] }> }) { const { path } = await params; const endpoint = `/api/forum/comments/${(path ?? []).join('/')}`; const res: ResultDto = await fetchJson(endpoint, { method: 'DELETE' }); return NextResponse.json(res); }